const { readdir, writeFile } = require("fs/promises")

const heroList = []

readdir("./images").then(files => {
  console.log(files.length)
  files.map(item => {
    const name = item.replace(".jpg", "")
    heroList.push({ name, path: `../images/${item}`, grade: 1 })
  })
})

setTimeout(() => {
  writeFile("./js/data.js", JSON.stringify(heroList), { encoding: "utf8", flag: "w" }).then(err => {
    if (err) {
      console.log("写入出错")
      console.log(err)
    } else {
      console.log("写入成功")
    }
  })
}, 0)